<template>
<div class="container">
  <ul class="tabs-header">
      <li v-for="(item,index) in tabs" :key="item" @click="handleClick(index)" :class="{active:curIndex==index}">
        {{item.name}}
      </li>
  </ul>
  <div class="content">
    <swiper @change="bindChange" class="swiper-container" :style="{height: clientHeight}" :current="curIndex">
      <swiper-item>
        <div :class="{cactive:curIndex==0}">
          <tab-base :id="id"/>
        </div>
      </swiper-item>

      <swiper-item>
        <div :class="{cactive:curIndex==1}">
          <tab-sucai :id="id"/>
        </div>
      </swiper-item>

      <swiper-item>
        <div :class="{cactive:curIndex==2}">
          <tab-appear/>
        </div>
      </swiper-item>
    </swiper>
 </div>
</div>
</template>
<script>
import mitem from '@/components/monster/Mitem'
import tabBase from '@/components/monster/desc/TabBase'
import tabSucai from '@/components/monster/desc/TabSucai'
import tabAppear from '@/components/monster/desc/TabAppear'

export default {
  props: [
    'id'
  ],
  data () {
    return {
      tabs: [{name: '基本信息'}, {name: '怪物素材'}, {name: '任务出现'}],
      curIndex: 0,
      imgUrls: ['http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175866434296.jpg', 'http://img06.tooopen.com/images/20160818/tooopen_sy_175833047715.jpg'
      ],
      clientHeight: '200px'
    }
  },
  methods: {
    handleClick (index) {
      this.curIndex = index
    },
    bindChange (e) {
      this.curIndex = e.mp.detail.current
    },
    getTabItemHeight (that) {
      wx.createSelectorQuery().select('.cactive').boundingClientRect(function (rect) {
        if (!rect) {
          setTimeout(() => {
            that.getTabItemHeight(that)
          }, 20)
        } else {
          that.clientHeight = rect.height + 'px'
        }
      }).exec()
    }
  },
  components: {
    mitem,
    tabBase,
    tabSucai,
    tabAppear
  },
  mounted () {

  },
  updated: function () {
    const that = this
    this.$nextTick(function () {
      that.getTabItemHeight(that)
    })
  }
}
</script>
<style scoped>
.tabs-header {
  list-style-type: none;
  display: flex;
  flex-direction: row;
}
.tabs-header li {
  float: left;
  flex-grow: 1;
  text-align: center;
  padding: 10px;
  color:#1d97c1;
  font-size: 14px;
  font-weight: bold;
  border-bottom: 3px solid #ffffff;
  transition: all .1s;
}
li.active {
  border-bottom-width: 100%;
  border-bottom: 3px solid #607D8B;
}
.content-item{
  width: 100%;
}
::-webkit-scrollbar{
  width: 0;
  height: 0;
  color: transparent;
}
.cactive{
  padding: 1px;
  background-color: #ffffff;
}
.tabs-header{
  background-color: #ffffff;
}
</style>
